﻿<!DOCTYPE html>
<!--风险类别管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.name" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{RiskCategoryManagement.ProductionActivityName+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.name.length<=0">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.code" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{RiskCategoryManagement.Code+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.code.length<=0">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{'上级分类'+mark.m}}
                                </template>
                                <treeselect v-model="Form.pid" :options="options" :flat="true" :normalizer="normalizer"
                                    :show-count="true" slot="suffix" style="line-height: 28px;" placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{RiskCategoryManagement.remarks+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.remarks"
                                    autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click=" parent.app.ListItem.dialogVisible = false">{{col.btnBack}}
                    </el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                options: [],
                mydata: RiskCategoryaaa,
                //父业传参
                id: '',
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    name: '',
                    code: '',
                    remarks: '',
                    pid: null
                },
                //表单验证
                rules: {
                    name: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],
                    code: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                normalizer: function (node) {
                    if (node) {
                        if (node.id == 0) {
                            return {
                                //下拉树顶级内容父级默认值
                                id: 0,
                                label: '当前为顶级类别'
                            }
                        }
                    }

                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            //if (mythis.id != null) {
                            //    for (var i = 0; i < parent.RiskCategoryaaa.length; i++) {
                            //        if (parent.RiskCategoryaaa[i].id == mythis.id) {
                            //            parent.RiskCategoryaaa[i] = mythis.Form;
                            //            break;
                            //        }
                            //    }
                            //    parent.app.ListItem.dialogVisible = false;
                            //}
                            //else {
                            //    parent.RiskCategoryaaa.push(mythis.Form);
                            //    parent.app.ListItem.dialogVisible = false;

                            //}
                            if (mythis.id != null) {
                                parent.app.childrenAdd = mythis.Form;
                            }
                            else {
                                mythis.Form.pid = mythis.Form.pid ? mythis.Form.pid : 0
                                parent.app.mydata.push(mythis.Form);
                            }
                            parent.app.ListItem.dialogVisible = false;
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/RiskCategoryManagement/get?id=' + this.id);
                }
            },
            mounted: function () {
                this.options = fn(this.mydata, "0");
                this.id = getUrlParam("id");
                this.getData();

            }
        });
    </script>
</body>

</html>